
import pymysql


class  pymysql_get():
    def __init__(self,host='124.221.52.199', port=3306, user='root', password='newzer.cn',
                                 charset='utf8',database='xbt_test'):
        self.sql_lj = pymysql.connect(host=host, port=port, user=user, password=password,
                                 charset=charset,database=database)
        self.cousor = self.sql_lj.cursor()
    def sql_get(self,sql):
        '''
        sql执行方法
        :param sql:sql语句
        :return:
        '''
        try:
            self.cousor.execute(sql)
            print("sql执行成功")
            data = self.cousor.fetchall()
            print(f"执行的结果为{data}")
        except Exception as e:
            print(f"错误类型为：{e}")
        finally:
            self.cousor.close()
            self.sql_lj.close()
if __name__ == '__main__':
    sql = "SELECT * FROM user_info  WHERE  mobile_num='16200000001';"
    ww=pymysql_get().sql_get(sql)